//
//  Find.m
//  视图控制器
//
//  Created by 18_李明明 on 14-11-15.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "Find.h"
#import "LabelAndTextField.h"
#import "Login.h"
@interface Find ()

@end

@implementation Find

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title =@"找回密码";
    // 邮箱输入框
    self.view.backgroundColor = [UIColor whiteColor];
    LabelAndTextField *mail = [[LabelAndTextField alloc] initWithFrame:CGRectMake(40, 80, 280, 40)];
//    mail.myLabel.textColor = [UIColor blackColor];
    mail.myLabel.text = @"邮箱";
    mail.myTextField.placeholder = @"电子邮箱";
    [self.view addSubview:mail];
    mail.myTextField.keyboardType = UIKeyboardTypeEmailAddress;
    [mail release];
    mail.myTextField.tag = 100;
    
    // 返回按钮
    UIButton *cancle = [UIButton buttonWithType:UIButtonTypeSystem];
    [cancle setTitle:@"返回" forState:UIControlStateNormal];
    cancle.frame = CGRectMake(60, 150, 40, 30);
    [cancle setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:cancle];
    [cancle addTarget:self action:@selector(targetC:) forControlEvents:UIControlEventTouchUpInside];
    
    // 确定按钮
    UIButton *certain = [UIButton buttonWithType:UIButtonTypeSystem];
    [certain setTitle:@"确定" forState:UIControlStateNormal];
    certain.frame = CGRectMake(130, 150, 40, 30);
    [self.view addSubview:certain];
    [certain addTarget:self action:@selector(targetcertain:) forControlEvents:UIControlEventTouchUpInside];
}

// 确定按钮事件
- (void)targetcertain:(UIButton *)certain
{
    UITextField *mail = (UITextField *)[self.view viewWithTag:100];
    if ([mail.text hasSuffix:@"@qq.com"]) {
        UIAlertView *alert = [[UIAlertView alloc] init];
        [alert initWithTitle:@"提示" message:@"已发送邮件请注意查收" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
        [alert release];
//        [self dismissViewControllerAnimated:YES completion:^{
//            
//        }];
        
        Login *login = [[Login alloc] init];
        [self.view removeFromSuperview];
        [self.parentViewController addChildViewController:login];
        [self.parentViewController.view addSubview:login.view];
        [login release];
    }else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的格式" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
    
}

// 取消按钮事件
- (void)targetC:(UIButton *)cancle
{
    Login *login = [self.navigationController.viewControllers objectAtIndex:0];
    [self.navigationController popToViewController:login animated:YES];
}
- (void)targetcancle:(UIButton *)cancle
{
//    [self dismissViewControllerAnimated:YES completion:^{
//    }];
    Login *login = [[Login alloc] init];
    [self.parentViewController addChildViewController:login];
    [self.view removeFromSuperview];
    [self.parentViewController.view addSubview:login.view];
    [login release];
}
// 点击空白回收键盘
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITextField *mail = (UITextField *)[self.view viewWithTag:100];
    [mail resignFirstResponder];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
